package com.gator.rabbitmq.pablo_rabbitmq.dead_queue;

import com.gator.rabbitmq.pablo_rabbitmq.utils.ConnectionUtils;
import com.rabbitmq.client.AMQP;
import com.rabbitmq.client.Channel;

import java.nio.charset.StandardCharsets;

/**
 * @Author PABLO
 * @Date 2022/6/5 21:35
 * @Desc
 */
public class Provider {
    public static final String EXCHANGE_NAME = "pablo-exchange-normal";
    public static final String NORMAL_ROUTING_KEY = "normal-routing-key";


    public static void main(String[] args) {
        Channel channel = ConnectionUtils.getConnectionAndChannel();
        try {
            AMQP.BasicProperties props = new AMQP.BasicProperties().
                    builder().
                    //设置消息ttl
                    expiration("10000").
                    build();

            for (int i = 1; i <= 10; i++) {
                String msg = "info-" + i;
                System.out.println("producer发送消息" + msg);
                channel.basicPublish(EXCHANGE_NAME,
                        NORMAL_ROUTING_KEY,
                        props,
                        msg.getBytes(StandardCharsets.UTF_8));
            }
        } catch (Exception e) {
            e.printStackTrace();
        }

    }
}
